﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages.WeightHistory
{
    public class HeightEdit : YouHP.Pages.PatientBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected WeightHistoryInfo WeightData = new WeightHistoryInfo();
        protected string Stature = "";
        protected new void HandleCommon()
        {
#if GENDATA
            WeightData = new WeightHistoryInfo();
            WeightData.Height = 1.65;
#else 
#endif
        }

        protected new void HandlePost()
        {
            double height = RequestTools.GetFormDouble("stature", -1);
            if (height < 0 || height > 3)
            {
                this.AddErrLine("身高信息错误");
                return;
            }
            bool succ = true;
#if GENDATA
            
#else
            succ = PatientBLL.Instance.UpdatePatientHeight(UserData.Id, height);
#endif
            if (succ)
            {
                this.AddMsgLine("身高修改成功");
                TempUrl = "/WeightHistory/Index.aspx";
                ResponseHelper.Redirect(GetUrl(TempUrl));
            }
            else
            {
                this.AddErrLine("身高修改失败");
            }
        }

        protected new void HandleGet()
        {
            //取得身高
            WeightData.Height = PatientBLL.Instance.GetPatientHeight(UserData.Id);
            if (WeightData.Height > 0) Stature = WeightData.Height.ToString();
        }
    }
}